﻿// Decompiled with JetBrains decompiler
// Type: SP1.DefinitionElement
// Assembly: SP1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 4A78F1E7-7FD5-407C-8917-5F99ECC43C34
// Assembly location: C:\Users\KasimGulcan\Desktop\Project\DynaCAD\bin\Debug\SP1.dll

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Xml;

namespace SP1
{
  public static class DefinitionElement
  {
    public static List<DefinitionElement.FilterElement> FEL = new List<DefinitionElement.FilterElement>();
    public static List<DefinitionElement.GradientElement> GEL = new List<DefinitionElement.GradientElement>();
    public static List<DefinitionElement.UIElements> UIL = new List<DefinitionElement.UIElements>();
    public static List<DefinitionElement.Styles> SL = new List<DefinitionElement.Styles>();
    public static string style = "stroke: #000000; fill: #000000";

    public static void Definition(XmlNode xn)
    {
      DefinitionElement.GradientElement gradientElement = new DefinitionElement.GradientElement();
      string Name = "void";
      foreach (XmlNode xn1 in xn.ChildNodes)
      {
        switch (xn1.Name)
        {
          case "linearGradient":
            gradientElement.GB = GradientElements.LinearGradient(xn1, out Name);
            gradientElement.Name = Name;
            DefinitionElement.GEL.Add(gradientElement);
            continue;
          case "radialGradient":
            gradientElement.GB = GradientElements.RadialGradient(xn1, out Name);
            gradientElement.Name = Name;
            DefinitionElement.GEL.Add(gradientElement);
            continue;
          case "g":
            StructuralElement.CanvasCreator(xn1);
            continue;
          case "circle":
            ShapeElements.CircleCreator(xn1);
            continue;
          case "ellipse":
            ShapeElements.EllipseCreator(xn1);
            continue;
          case "line":
            ShapeElements.LineCreator(xn1);
            continue;
          case "path":
            ShapeElements.PathCreator(xn1);
            continue;
          case "polygon":
            ShapeElements.PolygonCreator(xn1);
            continue;
          case "polyline":
            ShapeElements.PolylineCreator(xn1);
            continue;
          case "rect":
            ShapeElements.RectangleCreator(xn1);
            continue;
          case "filter":
            Effects.Effect(xn1);
            continue;
          default:
            continue;
        }
      }
    }

    public static UIElement Use(XmlNode xn)
    {
      string s = "void";
      double length1 = 0.0;
      double length2 = 0.0;
      UIElement element = new UIElement();
      foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap) xn.Attributes)
      {
        switch (xmlAttribute.Name)
        {
          case "x":
            length1 = AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value);
            continue;
          case "y":
            length2 = AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value);
            continue;
          case "xlink:href":
            for (int index = 0; index < DefinitionElement.UIL.Count; ++index)
            {
              if (DefinitionElement.UIL[index].Name == xmlAttribute.Value.Replace("#", ""))
              {
                element = XamlReader.Parse(XamlWriter.Save((object) DefinitionElement.UIL[index].UI)) as UIElement;
                break;
              }
            }
            continue;
          case "transform":
            s = xmlAttribute.Value;
            continue;
          default:
            continue;
        }
      }
      if (s != "void")
      {
        try
        {
          TransformGroup transformGroup = TransFormLibrary.TransformGroup(s);
          element.RenderTransform = (Transform) transformGroup;
        }
        catch
        {
          Console.WriteLine("Use Transform Gerçekleştirilemedi:" + s);
        }
      }
      Canvas.SetLeft(element, length1);
      Canvas.SetTop(element, length2);
      return element;
    }

    public struct FilterElement
    {
      public string Name;
      public Effect E;
    }

    public struct GradientElement
    {
      public string Name;
      public GradientBrush GB;
    }

    public struct UIElements
    {
      public string Name;
      public UIElement UI;
    }

    public struct Styles
    {
      public string Name;
      public string Style;
    }
  }
}
